package com.eshipenet.shipnet.edgeboxrpc.grpc;

import org.apache.ignite.cache.query.FieldsQueryCursor;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class FieldsQueryCursorMock implements FieldsQueryCursor {

    @Override
    public String getFieldName(int idx) {
        return null;
    }

    @Override
    public int getColumnsCount() {

        return 1;
    }

    @Override
    public List getAll() {
        List<String> list = new ArrayList<>();

        list.add("1");

        return list;

    }

    @Override
    public void close() {

    }

    @NotNull
    @Override
    public Iterator iterator() {

        final int[] i = {0};
        Iterator<List<?>> iterator = new Iterator<List<?>>() {
            @Override
            public boolean hasNext() {

                if (getAll().size() <= i[0]) {
                    return false;
                }

                i[0]++;
                return true;

            }

            @Override
            public List<?> next() {
                List<?> list = getAll();
                return list;
            }
        };


        return iterator;
    }
}
